<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>登录</title>
	</head>
	<body>
	
		<p>
			用户 <input type="text" name="username" id="username" value="" />
		</p>
		<p>
			密码 <input type="password" name="password" id="password" value="" />
		</p>
		<p>
			<input type="button" name="btn" id="btn" value="登录" />
			<a href="register.html">没有帐号去注册</a>
		</p>
	</body>
	<script src="js/jquery-3.2.1.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		$("input[name=btn]").click(function(){
			var user = $("input[name=username]").val();
			var pas = $("input[name=password]").val();
			$.ajax({
				type:"post",
				url:"http://h6.duchengjiu.top/shop/api_user.php",
				async:true,
				data:{
					status:"login",
					username:user,
					password:pas
				},
				success:function(data){
//					console.log(data);
//					console.log(data.data);
//					console.log(data.data.token);
					
					if(data.code==1001){
						alert("密码错误");
						return;
					}
					if(data.code==2002){
						alert("用户名不存在");
						return;
					}
					if(data.code==0){
						console.log(data.data);
						console.log(data.data.token);
						localStorage.token = data.data.token;
						localStorage.username = data.data.username;
						alert("登录成功");
						location.href = "index.html"
					}
				}
			});
		})
	</script>
</html>
